package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.config.minio.service.FileUploadService;
import com.atguigu.gmall.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author:ahang
 * @create:2022-09-28 22:28
 * @Description:
 */
@RestController
@RequestMapping("admin/product/")
public class FileController {

    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 文件上传
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("fileUpload")
    public Result uploadFile(@RequestPart("file")MultipartFile file) throws Exception {
        String url = fileUploadService.uploadFile(file);
        return Result.ok(url);
    }
}
